package org.lmw.mm.dao;

import java.util.List;

import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Model;
/**
 * 
 * 此类描述的是：   
 * @author: limengwei   
 * @version: 2014-6-5 上午11:48:07
 */
public class Post extends Model<Post> {
  private static final long serialVersionUID = 5021250170901392900L;
  public static final Post dao=new Post();
  
/**
 *   
 * 此方法描述的是：帖子列表   
 * @author: limengwei   
 * @version: 2014-6-6 下午1:53:43
 */
  public List<Post> findAll(int userId){
    String sql="select a.*,b.liked from mm_post a left join mm_like_post b on a.id=b.postId and b.userId=? order by id desc";
    return dao.find(sql,userId);
  }
  
  //赞+1
  public boolean like(int postId){
    
    int size=Db.update("update mm_post set likeCount=likeCount+1 where id=?",postId);
    if(size==1){
      return true;
    }
    return false;
  }
  
  //赞-1
  public boolean unLike(int postId){
    int size=Db.update("update mm_post set likeCount=likeCount-1 where id=?",postId);
    if(size==1){
      return true;
    }
    return false;
  }
  
}
